package customerEnter.Frame.JDBCDao.util;

import java.util.Collection;

import customerEnter.Frame.DaoDataTransmission.DaoFrameDMLBaseTransmission;
import customerEnter.Frame.DaoDataTransmission.DaoFramePameTransmission;
import customerEnter.Frame.Enum.FrameDataQueryUse;

/**
 * 
 * 
 * 类名称：DaoFrameUtil
 * 
 * 类描述：
 * 
 * 创建人：dy
 * 
 * 创建时间：2017-4-8 下午4:54:32
 * 
 */
public class DaoFrameUtil {
	/**
	 * 判斷用戶選擇的數據返回類型
	 */
	public static <T, K> boolean queryClassIsUse(Class<?> class1,
			DaoFramePameTransmission<T, K> daoFramePameTransmission) {
		boolean bool = false;
		if (Collection.class.equals(daoFramePameTransmission.getFrameDataQueryUse().getValue())) {
			bool = true;
		}
		return bool;
	}

	/**
	 * 判斷用戶選擇的數據返回類型
	 */
	public static FrameDataQueryUse queryClassIsUse(Class<?> class1) {
		FrameDataQueryUse frameDataQueryUse = null;
		if (FrameDataQueryUse.integer.getValue() == class1) {
			frameDataQueryUse = FrameDataQueryUse.integer;
		}
		if (FrameDataQueryUse.Integers.getValue() == class1) {
			frameDataQueryUse = FrameDataQueryUse.Integers;
		}
		if (FrameDataQueryUse.map.getValue() == class1) {
			frameDataQueryUse = FrameDataQueryUse.map;
		}
		if (FrameDataQueryUse.string.getValue() == class1) {
			frameDataQueryUse = FrameDataQueryUse.string;
		}
		if (FrameDataQueryUse.strings.getValue() == class1) {
			frameDataQueryUse = FrameDataQueryUse.strings;
		}
		return frameDataQueryUse;
	}

	/**
	 * 獲取 sql語句 —————— 參數 DataBase ：數據庫名稱 /DML： 數據庫操作 select insert delete
	 * update /Front ：查詢的東西/TableName:表名 /where:條件
	 */
	public static String SqlManage(String DataBase, String DML, String Front, String Rule, String TableName,
			String where) {
		return DataBase + " " + DML + " " + Front + "  " + Rule + " " + TableName + "  " + where.replace("\"", "");
	}

	/**
	 * 設置sql 和 類型 分頁
	 */
	public static <T, K> void ManageDaoFramePameTransmission(DaoFrameDMLBaseTransmission daoFrameDMLBaseTransmission,
			DaoFramePameTransmission<T, K> daoFramePameTransmission) {

		daoFramePameTransmission.SQL = DaoFrameUtil.SqlManage(daoFrameDMLBaseTransmission.getDataBase(),
				daoFrameDMLBaseTransmission.getDML(), daoFrameDMLBaseTransmission.getFront(),
				daoFrameDMLBaseTransmission.getRule(), daoFrameDMLBaseTransmission.getTableName(),
				daoFrameDMLBaseTransmission.getWhere());

		daoFramePameTransmission.pagingParametersCount = daoFrameDMLBaseTransmission.getPagingParametersCount();
		daoFramePameTransmission.cls = daoFrameDMLBaseTransmission.getClassName();
	}

}
